<template>
  <div id="app">
    <transition :name="routerTransition" mode="out-in" appear>
      <keep-alive include="Sellform,AddSellform,ApplyStoreRmList,PurchasecontractList,ScrapList,ChangesaList,ProduceplanList,PickingList,OutData,ProductionReport,TransferApplyList,ChangeContractPriceList">
        <router-view v-if="isRouterAlive"></router-view>
      </keep-alive>
    </transition>
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      routerTransition: 'fade',
      sessionOpenid: '',
      isRouterAlive: true
    }
  },
  watch: {
    // '$route':function() {
    // }
  },
  created() {
    window.addEventListener('setItem', ()=> {
      this.sessionOpenid = localStorage.getItem('openid');
    })

    //设置session openid，通过openid获取用户
    let openid = this.$route.query.openid;
    if (openid != undefined) {
      if (openid != this.sessionOpenid) {
        this.resetSetItem('openid', openid);
        //获取用户信息
        this.axios({
          method: 'get',
          url: '/system/Tuser!getUser.action?openid=' + openid
        }).then(response => {
          if (response.data.status == 'true') {
            this.resetSetItem('username', response.data.result.realname);
            this.resetSetItem('userid', response.data.result.guid);
          }
        });
      }
    } else {
      if(this.sessionOpenid == undefined) {
        $.alert('获取openid失败，请重新登录！')
      }
    }

  },
  mounted() {
  },
  methods: {
    reload () {
      this.isRouterAlive = false
      this.$nextTick(() => {
        this.isRouterAlive = true
      })
    }
  }
}
</script>

<style>
  .component-fade-enter-active, .component-fade-leave-active {
    transition: opacity .3s ease;
  }
  .component-fade-enter, .component-fade-leave-to
    /* .component-fade-leave-active for below version 2.1.8 */ {
    opacity: 0;
  }
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  height: 100%;
}
input[readonly="readonly"], input[disabled="disabled"] {
  color: #aaa;
}
.cellgroup {
  background: #fff;
  margin: 6px 0;
}
.fir.weui-cell:before {
  border-top: none;
}
.rj-cell-child-tit {
  font-size: 12px;
}
.weui-panel__bd {
  width: 100%;
}
  .weui-delbtn {
    color: red;
  }
</style>
